const { sequelize } = require('../../core/db')
const { Sequelize, Model } = require('sequelize')
const moment = require('moment');

// 定义项目管理模型
class Project extends Model {

}
// 初始项目管理模型
Project.init({
    id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    name: {
        type: Sequelize.STRING,
        allowNull: false,
        comment: '项目名称'
      },
      type:{
          type:Sequelize.INTEGER,
          allowNull:true,
          comment:"类型 1 PC 2 移动 3 小程序"
      },
      language:{
        type:Sequelize.STRING,
        allowNull:true,
        comment:"编写语言"
    },
    code:{
        type: Sequelize.STRING(64),
        unique:true,
        allowNull: false,
        comment:"项目编码"
      },
      apikey:{
        type: Sequelize.STRING,
        unique:true,
        allowNull: false,
        comment:"项目秘钥"
      },
      image:{
        type: Sequelize.STRING,
        allowNull: true,
        comment:"项目封面"
      },
      domain:{
        type: Sequelize.STRING(1024),
        allowNull: true,
        comment:"允许域名"
      },
      description:{
        type: Sequelize.STRING(1024),
        allowNull: true,
        comment:"描述" 
      },
      retainNameConfig:{
        type: Sequelize.STRING,
        allowNull: true,
        comment:"保留字段配置"
      },
      retainIdConfig:{
        type: Sequelize.STRING,
        allowNull: true,
        comment:"保留字段配置"
      },
      retainFieldConfig:{
        type: Sequelize.STRING,
        allowNull: true,
        comment:"保留字段配置"
      },
      moduleConfig:{
        type: Sequelize.STRING,
        allowNull: true,
        comment:"模块分类配置"
      },
      tenantId:{
        type: Sequelize.STRING,
        allowNull: true,
        comment:"租户Id"
      },
    created_at: {
        type: Sequelize.DATE,
        allowNull: false,
        comment:"创建日期",
        get() {
            return moment(this.getDataValue('created_at')).format('YYYY-MM-DD');
        }
    }
}, {
    sequelize,
    modelName: 'project',
    tableName: 'project'
})


module.exports = {
    Project
}
